<%@ page import="java.io.*, java.text.*, java.util.Date, java.sql.*, javax.servlet.*, javax.servlet.http.*, java.util.*" %>
<%!
public void check(String [] arr)
{
	for(int i=0;i<arr.length;i++)
	{
		while(arr[i] != null && arr[i].indexOf("\n") != -1)
		{
			arr[i] = arr[i].substring(0,arr[i].indexOf("\n")-1) + "<br/>" + arr[i].substring(arr[i].indexOf("\n")+1,arr[i].length());
		}
	}
}
%>
<%
String usernameS = (String) session.getAttribute("session_name");
String typeS = (String) session.getAttribute("type");
String idS = (String) session.getAttribute("ref_id");
String driver ="com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/projects";
String username = "ia";
String password = "123";
String [] id = null;
String [] title = null;
String [] desc = null;
String [] po = null;
String [] rb = null;
String [] tn = null;
String [] dl = null;
String [] pt = null;
String [] pk = null;
String [] er = null;
String [] ac = null;
String [] status = null;
String [] stStatus = null;
int size = 0;
int projN = 0;
try
{
	Class.forName(driver).newInstance();
	
	Connection connection = DriverManager.getConnection(url, username, password);
	
	Statement statement = connection.createStatement();
	Statement statement1 = connection.createStatement();
	
	String query="select count(*) from projects p where prof_id="+idS;
	String query1="select * from projects p where prof_id="+idS;
	String query3 = "select s.proj_id from student s, user_log_in l where s.id = l.ref_id and l.id ="+idS;
	ResultSet rs9 = statement.executeQuery(query3);
	if(rs9.next())
	{
		projN = rs9.getInt(1);
	}
	if(typeS.equals("student"))
	{
		if(projN == 0)
		{
			query = "select count(*) from projects p, user_log_in l, join_in j where j.st_id= l.ref_id and l.id="+idS+" and j.proj_id = p.id";
			query1 = "select p.* from projects p, user_log_in l, join_in j where j.st_id= l.ref_id and l.id="+idS+" and j.proj_id = p.id";
		}
		else
		{
			query = "select count(*) from student s, user_log_in l where s.id = l.ref_id and l.id ="+idS;
			query1 = "select * from projects where id="+projN;
		}	
	}
	
	ResultSet rs = statement.executeQuery(query);
	if(rs.next())
	{
		size = rs.getInt(1);
	}
	id = new String[size];
	title = new String[size];
	desc = new String[size];
	po = new String[size];
	rb = new String[size];
	tn = new String[size];
	dl = new String[size];
	pt = new String[size];
	pk = new String[size];
	er = new String[size];
	ac = new String[size];	
	status = new String[size];
	stStatus = new String[size];
	ResultSet rs1 = statement1.executeQuery(query1);
	for(int i=0 ;rs1.next();i++)
	{
		id[i] = rs1.getString("id");
		title[i] = rs1.getString("Title");
		desc[i] = rs1.getString("description");
		po[i] = rs1.getString("Project_Objectives");
		rb[i] = rs1.getString("Required_Background");
		tn[i] = rs1.getString("Tools_Needed");
		dl[i] = rs1.getString("Difficulty_Level");
		pt[i] = rs1.getString("Project_Type");
		pk[i] = rs1.getString("Project_Keywords");
		er[i] = rs1.getString("Expected_Results");
		ac[i] = rs1.getString("Additional_Comments");
		status[i] = rs1.getString("Status");
		if(typeS.equals("student") && projN != 0)
				stStatus[i] = "pend";
		
	}
	
	check(desc);
	check(po);
	check(rb);
	check(tn);
	check(dl);
	check(pt);
	check(pk);
	check(er);
	check(ac);
	
	connection.close();
		
}catch(ClassNotFoundException cnfe)
{
		out.println("<br>Couldn't find class file" + cnfe); 
}catch(SQLException sqle)
{
		out.println("<br>SQL Exception: " + sqle);
}catch(InstantiationException ie)
{
		out.println("<br>Instant exception : " + ie);
}catch(IllegalAccessException iae)
{
		out.println("<br>Illegal access exception : " + iae);
}
out.println("<script type='text/javascript'>");
out.println("function init() {");
for(int i = 0;i<size;i++) {
	out.println("descriptions["+i+"] = new Desc();");
	out.println("descriptions["+i+"].id = '"+ (id[i] != null ? id[i] : "") +"';");
	out.println("descriptions["+i+"].t = '"+ (title[i] != null ? title[i] : "") +"';");
	out.println("descriptions["+i+"].description = '"+(desc[i] != null ? desc[i] : "")+"';");
	out.println("descriptions["+i+"].po = '"+(po[i] != null ? po[i] : "")+"';");
	out.println("descriptions["+i+"].rb = '"+(rb[i] != null ? rb[i] : "")+"';");
	out.println("descriptions["+i+"].tn = '"+(tn[i] != null ? tn[i] : "")+"';");
	out.println("descriptions["+i+"].dl = '"+(dl[i] != null ? dl[i] : "")+"';");
	out.println("descriptions["+i+"].pk = '"+(pk[i] != null ? pk[i] : "")+"';");
	out.println("descriptions["+i+"].er = '"+(er[i] != null ? er[i] : "")+"';");
	out.println("descriptions["+i+"].status = '"+(status[i] != null ? status[i] : "")+"';");
	if(typeS.equals("student"))
		out.println("descriptions["+i+"].stStatus = '"+(stStatus[i] != null ? stStatus[i] : "")+"';");
}
out.println("}");
out.println("var usernameS='"+usernameS+"'");
out.println("var typeS='"+typeS+"'");
out.println("var sizeS='"+size+"'");

out.println("</script>");

%>
<div id="rightMenu" style="position:absolute"></div>
<table style="text-align: left" border="0" width="100%" cellspacing="0" cellpadding="0" class="all">
	<%
	for(int i=0;i<id.length;i++)
	{
	%>
	<tr>
		<td id="td<%=i%>" valign="top" class="normal">
			<div id="ccc<%=i%>"><div id="title<%=i%>" class="title" width="100%" onMouseOver="mouse(<%=i%>)" onMouseOut="mouseo(<%=i%>)" onclick="clicked(<%=i%>)"></div></div>
		</td>
	</tr>
	<%
	}
	%>
</table>
